#include "guiGame.h"
//-----------------------------
guiGame::guiGame(gamePlay* _myGame, playersManager*			_myPlayersManager)
{
	myGame = _myGame;
	myPlayersManager =	_myPlayersManager;
}
//-----------------------------

void guiGame::draw()
{
	drawBuilding();
	drawTitles();
	drawPlayers();
	drawControls();
}

//-----------------------------

void guiGame::drawBuilding()
{

	for(int h=0; h< myGame->getTotalWidthWindows();h++)
	{
		for(int w=0; w< myGame->getTotalHeightWindows();w++)
		{
			ofPushMatrix();
			ofTranslate(490+h*9,200+w*9);
			ofColor myWindowColor = myGame->getWindowColor(w,h);
			ofSetColor(myWindowColor.r,myWindowColor.g,myWindowColor.b);
			ofRect(0,0,8,7);
			ofSetColor(0,0,0);
			ofPopMatrix();
		}
		if(h==9)
		{ 
			ofSetColor(0,0,0);
		}
	}
}
//-------------------------------

void guiGame::drawTitles()
{
	ofSetColor(30,30,30);
	ofRect(50,80,480,50);
	ofSetColor(255,255,0);
	ofDrawBitmapString("Pixel Killers - Mar Canet 2009",50,100);
	ofDrawBitmapString("Urban interface - Interface Culture (Kunst University Linz)",50,120);
	ofSetColor(0,0,0);
	ofDrawBitmapString("DISPLAY GAME ZONES - From West Side",50,180);
}
//-------------------------------

void guiGame::drawPlayers()
{
//----------------------------------------------------------
	// titles
	//----------------------------------------------------------
	// team A
	ofPushMatrix();
	ofTranslate(50,200);
	ofSetColor(0,255,0);
	ofRect(0,0,166,420);
	ofSetColor(0,0,0);
	
	for(int i=0;i<19;i++)
	{	
		for(int j=0;j<4;j++)
		{
			int id = myPlayersManager->getIdScreenPos(j,i,'a');
			if( id!=-1 && myPlayersManager->getLife(id,'a') ){
				ofSetColor(255,255,255);
			}else{
				ofSetColor(0,0,0);
			}
			ofPushMatrix();
			ofTranslate(j*42,22*i);
			ofRect(0,0,40,20);
			ofSetColor(0,0,255);
			if(id!=-1)ofDrawBitmapString("id."+ofToString(id),0,15);
			ofPopMatrix();
		}
	}
	ofPopMatrix();
	//----------------------------------------------------------
	// team B
	ofPushMatrix();
	ofTranslate(280,200);
	ofSetColor(255,0,0);
	ofRect(0,0,166,420);
	ofSetColor(0,0,0);

	for(int i=0;i<19;i++)
	{
		for(int j=0;j<4;j++)
		{
			
			int id = myPlayersManager->getIdScreenPos(j+6,i,'b');
			if( id!=-1 && myPlayersManager->getLife(id,'b') ){
				ofSetColor(255,255,255);
			}else{
				ofSetColor(0,0,0);
			}
			ofPushMatrix();
			ofTranslate(j*42,22*i);
			ofRect(0,0,40,20);
			ofSetColor(0,0,255);
			if(id!=-1)ofDrawBitmapString("id."+ofToString(id),0,15);
			ofPopMatrix();
		}
	}
	ofPopMatrix();
}
//---------------------------------------------------

void guiGame::drawControls()
{
	// control panel: reset game, start
	ofSetColor(30,30,30);
	ofRect(50,685,180,20);
	ofSetColor(255,255,0);
	ofDrawBitmapString("RESET GAME - press 'R'",50,700);
	ofSetColor(30,30,30);
	ofRect(50,715,180,20);
	ofSetColor(255,255,0);
	ofDrawBitmapString("START GAME - press 'S'",50,730);
	ofDrawBitmapString("GREEN:["+ofToString(myGame->getPointsTeamA())+"/19] RED:["+ofToString(myGame->getPointsTeamB())+"/19]",50,650);
	if(myGame->getPointsTeamA()==18)
	{
		ofDrawBitmapString("WINNER GREEN TEAM!!",50,640);
	}
	if(myGame->getPointsTeamB()==18){
		ofDrawBitmapString("WINNER RED TEAM!!",290,640);
	}
	ofDrawBitmapString("PLAYERS GREEN:["+ofToString(myPlayersManager->getTotalLifePlayers(1))+"/4] PLAYERS RED:["+ofToString(myPlayersManager->getTotalLifePlayers(2))+"/4]",50,670);
}